#ifndef __SOFTTIMER_H__
#define __SOFTTIMER_H__

#if PLAT_SOFT_TIMER_EN > 0

#include "framework_config.h"
#include <functional>
#include "plat/nonecopyable.h"
#include <list>

class SoftTimer : public NoneCopyable
{
public:
    enum class TimerType 
    {
        OneShot = 0,
        Period
    };

public:
    SoftTimer();
    SoftTimer(int interval, TimerType type);
    virtual ~SoftTimer();

public:
    void SetInterval(int interval);
    int GetInterval();
    void SetTimerType(TimerType type);
    TimerType GetTimerType();

    void SetElapsed(std::function<void(SoftTimer &timer)> func);
    void Start();
    void Stop();
    bool IsRunning();

    //1ms 
    static void Run();

private:
    void AddToTimerList(SoftTimer *timer);
    void RemoveFromTimerList(SoftTimer *timer);
    void Update();

private:
    int m_interval = 10;
    int m_currentMs = 0;
    bool m_isRunning = false;
    std::function<void(SoftTimer &timer)> m_func = nullptr;
    TimerType m_timerType = TimerType::Period;

    static std::list<SoftTimer*> m_timers;
};
#endif 

#endif // __SOFTTIMER_H__
